<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch">
      <el-form-item label="车牌号" prop="licenseNum">
        <el-input v-model="queryParams.licenseNum" placeholder="请输入车牌号" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
      <!-- <el-form-item label="到期状态" prop="isEnd">
        <el-select
          v-model="queryParams.isEnd"
          filterable
          placeholder="请选择到期状态"
        >
          <el-option label="全部" :value="null" />
          <el-option label="到期" :value="true" />
          <el-option label="未到期" :value="false" />
        </el-select>
      </el-form-item> -->
      <el-form-item label="品牌" prop="brand">
        <el-input v-model="queryParams.brand" placeholder="请输入品牌" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>

      <!-- <el-form-item label="到期日期">
        <el-date-picker
          v-model="dateRange"
          value-format="yyyy-MM-dd HH:mm:ss"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          style="width: 240px"
          :default-time="['00:00:00', '23:59:59']"
        ></el-date-picker>
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table @selection-change="handleSelectionChange" fit v-loading="loading" border :data="dataList">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" type="index" />
      <el-table-column label="车牌号" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <el-link type="primary">{{ scope.row.licenseNum }}</el-link>
        </template>
      </el-table-column>
      <el-table-column :show-overflow-tooltip="true" width="120" label="品牌类型" prop="brand" />
      <el-table-column :show-overflow-tooltip="true" label="车辆类型">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.sys_driver_type" :value="scope.row.driverTypeValue" />
        </template>
      </el-table-column>

      <!-- <el-table-column label="购买日期" prop="car.buyDate" /> -->
      <el-table-column show-overflow-tooltip width="150" label="注册日期" prop="checkDate">
        <template slot-scope="scope">
          {{ parseTime(scope.row.carInfoBo.yearCheckDate, "{y}-{m}-{d}") }}
        </template>
      </el-table-column>
      <el-table-column show-overflow-tooltip width="150" label="年检日期" prop="checkDate">
        <template slot-scope="scope">
          {{ parseTime(scope.row.carInfoBo.nextYearCheckDate, "{y}-{m}-{d}") }}
        </template></el-table-column>
      <!-- <el-table-column label="到期状态" prop="status">
        <template slot-scope="scope">
          {{ scope.row.status }}
        </template>
      </el-table-column> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" width="200" fixed="right">
        <template slot-scope="scope">

          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
            v-hasPermi="['vehicle:checkUp:edit']">年检</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script>
import { delCarYearCheck } from "@/api/car/carYearCheck.js";
import { listCar } from "@/api/car/car.js";
import { userSelect, deptTreeSelect } from "@/api/system/user.js";

export default {
  name: "remind",
  dicts: ["sys_driver_type"],

  data() {
    return {
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      dataList: [],
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        status: 1,
        licenseNum: undefined,
        checkState: 1,
      },
      // 日期范围
      dateRange: [],

      userList: [],
      deptOptions: [],
    };
  },
  created() {
    this.getList();
    this.userSelect();
    this.getDeptTree();
  },
  methods: {
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.carYearCheckId);
      this.single = selection.length != 1;
      this.multiple = !selection.length;
    },

    // /** 修改按钮操作 */
    // handleUpdate(row) {
    //   const configId = row.carYearCheckId || this.ids;
    //   this.$router.push("./addRecord?isEdit=true&id=" + configId);
    // },
    /** 修改按钮操作 */
    handleUpdate(row) {
      const configId = row.carYearCheckId || this.ids;
      this.$router.push("./addCheckUp?id=" + configId + "&carId=" + row.carId + "&driverTypeName=" + row.driverTypeName + 
      '&brand=' + row.brand + '&nickName='+ row.nickName + '&driverId='+ row.driverId +"&driverTypeValue="+ row.driverTypeValue+"&licenseNum="+ row.licenseNum);
    },
    handleDetail(row) {
      this.$router.push("./addRecord?isInfo=true&id=" + row.carYearCheckId);
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const configId = row.carYearCheckId || this.ids;

      this.$modal
        .confirm('是否确认删除ID为"' + configId + '"的数据项？')
        .then(function () {
          return delCarYearCheck(configId);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => { });
    },
    handleAdd() {
      this.$router.push("./addRecord");
    },
    /** 查询部门下拉树结构 */
    getDeptTree() {
      deptTreeSelect().then((response) => {
        this.deptOptions = response.data;
      });
    },
    userSelect() {
      userSelect().then((response) => {
        this.userList = response.data;
      });
    },
    /** 查询列表 */
    getList() {
      this.loading = true;
      listCar(
        this.addDateRangeTime(
          this.queryParams,
          this.dateRange,
          "startEndDate",
          "endEndDate"
        )
      ).then((response) => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
  },
};
</script>
<style lang="scss" scoped>
::v-deep .el-dialog__body {
  img {
    width: 100%;
  }
}
</style>
